home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / Level 0 Macintosh 29Sep94 / Memory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  2.4 KB  |  74 lines  |  [TEXT/KAHL]

  1. /* Memory.h */
  2.  
  3. #ifndef Included_Memory_h
  4. #define Included_Memory_h
  5.  
  6. /* Memory module depends on: */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* MyMalloc */
  12.  
  13. /* if the following symbol is defined in the header, then all allocated */
  14. /* pointers will be added to a table to see if they are being disposed twice. */
  15. /* #define MEMDEBUG */
  16.  
  17. /* routine for changing the tag associated with an allocated object. */
  18. #if MEMDEBUG
  19.     #if !DEBUG
  20.         #error "MEMDEBUG can't be enabled if DEBUG is disabled!"
  21.     #endif
  22.     /* alter the identification tag on an object */
  23.     void        SetTag(void* TheRef, char* TheTag);
  24. #else
  25.     #define SetTag(crud1,crud2) ((void)0)
  26. #endif
  27.  
  28. #if DEBUG
  29.     /* debugging code */
  30.     /* allocate a single-indirection block of memory; returns NIL if it can't be done */
  31.     #define AllocPtrCanFail(Size,Tag) EepAllocPtr((Size),(Tag))
  32.     /* verify that a pointer is actually valid; abort the program with an error */
  33.     /* message if it isn't.  This disappears when the DEBUG macro is undefined */
  34.     void        CheckPtrExistence(void* ThePointer);
  35.     /* checks the range of access of a ptr to see if it is within the ptr's size */
  36.     /* AccessSize is how large an 'object' will be accessed.  Pass sizeof(type) to it. */
  37.     void        PRNGCHK(void* ThePointer, void* EffectiveAddress, signed long AccessSize);
  38. #else
  39.     /* production code */
  40.     #define AllocPtrCanFail(Size,Tag) EepAllocPtr((Size))
  41.     #define CheckPtrExistence(brapp) ((void)0)
  42.     #define PRNGCHK(Poin,Addr,Mode) ((void)0)
  43. #endif
  44.  
  45. /* Initialize the memory subsystem.  Must be called at the beginning of the */
  46. /* program before any other modules are initialized */
  47. MyBoolean    Eep_InitMemory(void);
  48.  
  49. /* clean up anything that must be disposed of before the program terminates */
  50. /* and create a list of pointers that are still allocated.  This */
  51. /* must be called as the last instruction in the program */
  52. void            Eep_FlushMemory(void);
  53.  
  54. /* these functions are local to the implementation */
  55. #if DEBUG
  56.     /* debugging code */
  57.     char*            EepAllocPtr(long Size, char* Tag);
  58. #else
  59.     /* production code */
  60.     char*            EepAllocPtr(long Size);
  61. #endif
  62.  
  63. /* Dispose of a block of memory that is no longer needed */
  64. void            ReleasePtr(char* ThePtr);
  65.  
  66. /* obtain the size of the specified Ptr in bytes */
  67. long            PtrSize(char* p);
  68.  
  69. /* resize a pointer.  The pointer might have to be entirely reallocated, in which */
  70. /* case the new one will be returned and the old one will be disposed. */
  71. char*            ResizePtr(char* ThePointer, long NewSize);
  72.  
  73. #endif
  74.